import { User } from "@/types/api";
import { create } from "zustand";

export const useStore = create<{
    token: string;
    userInfo: User.UserItem;
    collapsed: boolean;
    updateToken: (token: string) => void;
    updateUserInfo: (userInfo: User.UserItem) => void;
    updateCollapsed: () => void;
}>(set => ({
    token: "",
    userInfo: {
        createId: 0,
        deptId: "",
        deptName: "",
        job: "",
        mobile: "",
        role: 0,
        roleList: 0,
        state: 0,
        userEmail: "",
        userId: 0,
        userImg: "",
        userName: "",
        _id: "",
    },
    collapsed: false,
    updateToken(token: string) {
        set({ token });
    },
    updateUserInfo(userInfo: User.UserItem) {
        set({ userInfo });
    },
    updateCollapsed() {
        set(state => {
            return {
                collapsed: !state.collapsed,
            };
        });
    },
}));
